// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2011/1/27 16:32:23
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   inputGatheringDetailTask_invoiceDetailDatasetListener.java

package com.efesco.finance.gathering;

import com.bstek.dorado.common.DoradoContext;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.SqlDataset;
import com.efesco.common.Tools;
import com.efesco.system.User;

public class inputGatheringDetailTask_invoiceDetailDatasetListener extends AbstractDatasetListener
{

    public inputGatheringDetailTask_invoiceDetailDatasetListener()
    {
    }

    public boolean beforeLoadData(Dataset dataset)
        throws Exception
    {
        String user_id = "";
        String sql = "";
        String tbName = "";
        DoradoContext context = DoradoContext.getContext();
        Object obj = context.getAttribute(5, "User");
        if(obj != null)
        {
            User user = (User)obj;
            user_id = user.getUserId()+"";
            sql = "SELECT cmp.company_chinese_name,i.invoice_code,i.invoice_amount,to_char(i.invoice_date,'yyyy-mm-dd') invoice_date,to_char(i.arrive_date,'yyyy-mm-dd') input_date,i.payment_type,i.if_effect,h.ought_month,o.ought_amount,o.payment_version_id,h.gathering_amount,h.rate_odds,h.gathering_memo,h.hr_invoice_detail_id,h.pre_month,h.payment_type oType,o.ought_receive_id,i.single_company_id,h.pay_send_ids FROM s_hr_invoice_detail h,s_single_company cmp,s_invoice i,s_ought_receive o,s_workitem wi WHERE i.INVOICE_ID = h.INVOICE_ID and cmp.single_company_id=o.single_company_id and o.single_company_id = i.single_company_id AND (h.ought_month=o.ought_month or h.pre_month=o.ought_month) and o.payment_type=h.payment_type  and h.pay_send_ids=o.pay_send_ids and  i.if_effect<>2 and wi.process_ins_id=h.process_ins_id  and wi.participant='" + user_id + "'";
            if(!Tools.toStr(dataset.parameters().getString("singleCompanyId")).equals(""))
                sql = sql + " and cmp.single_company_id = '" + Tools.toStr(dataset.parameters().getString("singleCompanyId")) + "' ";
            sql = sql + " order by o.ought_month,cmp.COMPANY_CHINESE_NAME ";
            SqlDataset sqlDataset = (SqlDataset)dataset;
            sqlDataset.setSql(sql);
        }
        return true;
    }
}